#include "shape.h"
namespace Tetris{

class MyRand;
Shape::Shape(int r,int c){
	this->color = 1;
	this->row = r;
	this->col = c;
	this->p_arr = new bool[this->row * this->col];
	this->Clear();
}
int Shape::ColorStyle() const{
	return this->color;
}
Shape::Shape(){
	this->color = 1;
	this->row = 4;
	this->col = 4;
	this->p_arr = new bool[this->row * this->col];
	this->Clear();
}

Shape::Shape(const Shape& shape){
	this->col = shape.col;
	this->row = shape.row;
	this->p_arr = new bool[this->row * this->col];
	this->Clear();
}

Shape::~Shape()
{
	delete []this->p_arr;
}

void Shape::Clear(){
	int len = this->row * this->col;
	for(int i=0;i<len;++i)
		this->p_arr[i] = false;
}

int Shape::Row() const{
	return this->row;
}

int Shape::Column() const{
	return this->col;
}

bool Shape::GetValue(int x,int y) const {
	return this->p_arr[x + y * this->Column()];
}

int Shape::GetMaxY() const{
	for(int y = this->Row() - 1; y >= 0; --y){
		for(int x = this->Column() - 1; x >= 0; --x){
			if(this->GetValue(x,y))
				return y;
		}
	}
	return this->Row() - 1;
}

int Shape::GetMinX() const{
	for(int x = 0; x < this->Column(); ++x){
		for(int y = this->Row() - 1; y >= 0; --y){
			if(this->GetValue(x,y))
				return x;
		}
	}
	return 0;
}

int Shape::GetMaxX() const{
	for(int x = this->Column() - 1; x >= 0; --x){
		for(int y = 0; y < this->Row(); ++y){
			if(this->GetValue(x,y))
				return x;
		}
	}
	return this->Column() - 1;
}
int Shape::GetMinY() const{
	for(int y = 0; y < this->Row(); ++y){
		for(int x = this->Column() - 1; x >= 0; --x){
			if(this->GetValue(x,y))
				return y;
		}
	}
	return 0;
}

}